package cn.org.intelli.lims.o2oa.model;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.fun.DataProxy;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.ViewType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
import java.util.UUID;

@Getter
@Setter
@Entity
@Table(name = "lims_duty")
@SQLDelete(sql = "update lims_duty set deleted = true, delete_time = now() where id = ?")
@Erupt(name = "职责信息", dataProxy = Duty.class, filter = @Filter("Duty.deleted = false"))
public class Duty implements DataProxy<Duty> {
    @Id
    @EruptField(views = @View(title = "", type = ViewType.QR_CODE))
    private String id;
    @EruptField(views = @View(title = "名称"), edit = @Edit(title = "名称", search = @Search))
    private String name;
    @Column(name = "delete_time")
    private Date deleteTime;
    private Boolean deleted = false;

    @Override
    public void beforeAdd(Duty duty) {
        if (duty.getId() == null) {
            duty.setId(UUID.randomUUID().toString());
        }
    }
}
